package com.qf.controller;

import com.qf.common.R;
import com.qf.entity.LoginUser;
import com.qf.service.UserService;
import lombok.extern.slf4j.Slf4j;
import com.qf.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/user")
@Slf4j
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/login")
    public R login(@RequestBody LoginUser loginUser){
        log.debug("登录用户：{}",loginUser);
        User user = userService.login(loginUser);
        if(user == null){
            return R.fail("登陆失败");
        }
        return R.ok(user);
    }
}
